#ifndef DHD_FRONTEND_CONFIG
#define DHD_FRONTEND_CONFIG

#include <set>
#include <string>
#include <stdexcept>

namespace dhd
{
namespace client
{

/* Required format:
 * 
 *     srp <username>:<password_file>
 * 
 *     server <hostname>:<port> [use_srp] [use_ssl]
 * 
 * Only 0 or 1 srp line is permitted.
 * Multiple server lines are permitted
 * Blank lines are permitted
 * Lines beginning with # are comment lines
 * 
 */

class ConfigurationError : public std::runtime_error
{
 public:
   int line;
   ConfigurationError( const std::string & what, int _line ) : std::runtime_error(what), line(_line) {}
   ~ConfigurationError() throw() {}
};


class ClientConfig;


struct ServerCFG
{
    std::string      hostname;
    int              port;
    bool             use_ssl;
    bool             use_srp;
    std::string      ssl_file; // TODO: remove this?
   
    ClientConfig * frontend_cfg;
   
    ServerCFG() : port(0), use_ssl(false), use_srp(false), frontend_cfg(0) {}
    
    bool operator<( const ServerCFG & other ) const 
    {
        if (hostname == other.hostname)
            return port < other.port;
        else
            return hostname < other.hostname;
    }
};



class ClientConfig
{   
 public:
   
   // throws ConfigurationError
   ClientConfig( const std::string & cfg_file );
   
   
   std::set< ServerCFG > servers;
   std::string           srp_username;
   std::string           srp_password_file;
   std::string           srp_password;
};

   
} // end namespace dhd::client
} // end namespace dhd



#endif